################################################################################
# \file bsp.mk
#
################################################################################
# \copyright
# Copyright 2018-2023 Cypress Semiconductor Corporation (an Infineon company) or
# an affiliate of Cypress Semiconductor Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################

ifeq ($(WHICHFILE),true)
$(info Processing $(lastword $(MAKEFILE_LIST)))
endif

# Define default type of bootloading method [single, dual]
# single -> CM4 only, multi -> CM0 and CM4
SECURE_BOOT_STAGE?=single

# Any additional components to apply when using this board.
# Add secure CM0P image in single stage.
ifeq ($(SECURE_BOOT_STAGE), single)
BSP_COMPONENTS:=CM0P_SECURE
endif

# Any additional defines to apply when using this board.
BSP_DEFINES:=CY_USING_HAL

ifeq ($(SECURE_BOOT_STAGE),single)
BSP_LINKER_SUFFIX=
CY_SECURE_POLICY_NAME?=policy_single_CM0_CM4
else
# In multi-boot, we want the "single" linker script for CM4 because that only links
# in the CM4 image, allowing the CM0 image to be loaded separately.
BSP_LINKER_SUFFIX=$(if $(call mtb_equals,$(MTB_RECIPE__CORE),CM4), _single,)
CY_SECURE_POLICY_NAME?=policy_multi_CM0_CM4
endif

# Specify the path to the linker script to use
ifeq ($(TOOLCHAIN),GCC_ARM)
	BSP_LINKER_SCRIPT_EXT:=ld
else ifeq ($(TOOLCHAIN),ARM)
	BSP_LINKER_SCRIPT_EXT:=sct
else ifeq ($(TOOLCHAIN),IAR)
	BSP_LINKER_SCRIPT_EXT:=icf
endif

MTB_BSP__LINKER_SCRIPT=$(MTB_TOOLS__TARGET_DIR)/COMPONENT_$(MTB_RECIPE__CORE)/TOOLCHAIN_$(TOOLCHAIN)/linker$(BSP_LINKER_SUFFIX).$(BSP_LINKER_SCRIPT_EXT)

#Define the toolchain path
ifeq ($(TOOLCHAIN),ARM)
TOOLCHAIN_PATH=$(MTB_TOOLCHAIN_ARM__BASE_DIR)
else
TOOLCHAIN_PATH=$(MTB_TOOLCHAIN_GCC_ARM__BASE_DIR)
endif

# Python path definition
CY_PYTHON_REQUIREMENT=true

POST_BUILD_CM0_LIB_PATH=$(SEARCH_cat1cm0p)/COMPONENT_CAT1A/COMPONENT_CM0P_SECURE
POST_BUILD_BSP_LIB_PATH_INTERNAL=$(SEARCH_TARGET_$(TARGET))

POST_BUILD_BSP_LIB_PATH=$(call mtb_path_normalize,$(POST_BUILD_BSP_LIB_PATH_INTERNAL))

# BSP-specific post-build action
CY_BSP_POSTBUILD=$(CY_PYTHON_PATH) $(POST_BUILD_BSP_LIB_PATH)/psoc64_postbuild.py \
				--core $(MTB_RECIPE__CORE) \
				--secure-boot-stage $(SECURE_BOOT_STAGE) \
				--policy $(CY_SECURE_POLICY_NAME)\
				--target cyb06xx7 \
				--toolchain-path $(TOOLCHAIN_PATH) \
				--toolchain $(TOOLCHAIN) \
				--build-dir $(MTB_TOOLS__OUTPUT_CONFIG_DIR) \
				--app-name $(APPNAME) \
				--cm0-app-path $(POST_BUILD_CM0_LIB_PATH) \
				--cm0-app-name psoc6_01_cm0p_secure



################################################################################
# ALL ITEMS BELOW THIS POINT ARE AUTO GENERATED BY THE BSP ASSISTANT TOOL.
# DO NOT MODIFY DIRECTLY. CHANGES SHOULD BE MADE THROUGH THE BSP ASSISTANT.
################################################################################

# Board device selection. MPN_LIST tracks what was selected in the BSP Assistant
# All other variables are derived by BSP Assistant based on the MPN_LIST.
MPN_LIST:=
